Fix duplicate check losing form params and nested attributes#1369
Fix duplicate check losing form params and nested attributes#1369
Conversation
Replace redirect_to with render :check_duplicates so all POST params stay available in the request. Add hidden_fields_for_params helper to recursively render nested params as hidden inputs for the "Create anyway" form. "Go back" link now navigates to the new form with params to repopulate fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Passing nested params (sectors, addresses) via query string to the new form didn't repopulate associations. Browser history.back() restores the original form state including all fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Opens the user's email client with a pre-filled subject and the shareable GET URL so a colleague can review the potential duplicates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Skip file uploads (avatar) and blank id fields in hidden_fields_for_params so nested attributes (affiliations, addresses, sectors, phones) are preserved correctly through the Create anyway form. Show a note when an avatar was uploaded that it will need to be re-added. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cocoon's JS takes wrapper.firstElementChild from the template HTML. The hidden kind field was before the .nested-fields div, so cocoon only inserted the lone <input> and discarded the actual form fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace history.back() with POST to retry_new on both people and users duplicate check interstitials so nested attributes (sectors, addresses, phones, affiliations) are preserved when going back - Remove debug logging from controllers - Remove debug logging from cocoon JS - Add explicit partial path for phone link_to_add_association - Add request specs for retry_new and Create anyway with nested attrs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
from claude: |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@jmilljr24 this is the "real" dupe check update |
|
When I "go back" Org affiliation name is displaying the id, not the name. Everything looked ok for Person. I saw some code regarding avatars but I never got it to display in the UI. It sounds like if an avatar is added in the form, you lose it if there is a dup? Kinda of unfortunate but lower on the list of priorities as Admin at this point probably are not adding avatars for people, the person will do it themselves. I'm good with this approach as is but I do think there is a better UX we could come up with in the future. Regarding the AI quote, it doesn't align with the flow/implementation I can envision. It's also confusing/mixing turbo frames vs turbo streams. I wouldn't dismiss other alternative idea based off that response. |
* Retain form params through duplicate check interstitial pages Replace redirect_to with render :check_duplicates so all POST params stay available in the request. Add hidden_fields_for_params helper to recursively render nested params as hidden inputs for the "Create anyway" form. "Go back" link now navigates to the new form with params to repopulate fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Use history.back() for Go back link on duplicate check pages Passing nested params (sectors, addresses) via query string to the new form didn't repopulate associations. Browser history.back() restores the original form state including all fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add Ask a colleague mailto link on duplicate check pages Opens the user's email client with a pre-filled subject and the shareable GET URL so a colleague can review the potential duplicates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix nested attributes and avatar handling on duplicate check page Skip file uploads (avatar) and blank id fields in hidden_fields_for_params so nested attributes (affiliations, addresses, sectors, phones) are preserved correctly through the Create anyway form. Show a note when an avatar was uploaded that it will need to be re-added. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix Add phone button by moving hidden field inside nested-fields div Cocoon's JS takes wrapper.firstElementChild from the template HTML. The hidden kind field was before the .nested-fields div, so cocoon only inserted the lone <input> and discarded the actual form fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add retry_new action to preserve form data through Go back - Replace history.back() with POST to retry_new on both people and users duplicate check interstitials so nested attributes (sectors, addresses, phones, affiliations) are preserved when going back - Remove debug logging from controllers - Remove debug logging from cocoon JS - Add explicit partial path for phone link_to_add_association - Add request specs for retry_new and Create anyway with nested attrs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix users dupe check spec: replace nonexistent trait with user: nil Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix users dupe check spec: eagerly create person to avoid count mismatch Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Closes #1023
What is the goal of this PR and why is this important?
redirect_towhich discards POST paramshistory.back()which doesn't restore dynamically-added Cocoon fieldsHow did you approach the change?
redirect_towithrender :check_duplicatesto preserve POST params in controller statehidden_fields_for_paramshelper to round-trip all form params (including nested attributes) through hidden fields on the interstitial pagehistory.back()"Go back" with aretry_newPOST action that rebuilds@personfrom params and re-renders thenewform with nested objects pre-populatedretry_newcollection route and controller action for both people and userskindfield was outside the.nested-fieldsdiv, so cocoon'sfirstElementChildgrabbed only the<input>and discarded the form fieldsidfields andUploadedFileobjects in hidden field generationUI Testing Checklist
Anything else to add?
.nested-fieldsdiv) is a separate commit that fixes a pre-existing bug